package com.atguigu.system.service.impl;

import com.atguigu.model.system.SysLoginLog;
import com.atguigu.model.system.SysOperLog;
import com.atguigu.model.vo.SysOperLogQueryVo;
import com.atguigu.system.mapper.SysOperLogMapper;
import com.atguigu.system.service.AsyncLoginLogService;
import com.atguigu.system.service.AsyncOperLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * ClassName: AsyncOperLogServiceImpl
 * Description:
 *
 * @Author CZX
 * @Create 2024/3/14 17:20
 * @Version 1.0
 */
@Service
public class AsyncOperLogServiceImpl implements AsyncOperLogService {
    @Autowired
    private SysOperLogMapper sysOperLogMapper;
    @Override
    public void saveSysLog(SysOperLog sysOperLog) {
        sysOperLogMapper.insert(sysOperLog);
    }

    @Override
    public IPage<SysOperLog> selectPage(Long page, Long limit, SysOperLogQueryVo sysOperLogQueryVo) {
        //创建page对象
        Page<SysOperLog> pageParam = new Page(page, limit);
        //获取条件值
        String title = sysOperLogQueryVo.getTitle();
        String operName = sysOperLogQueryVo.getOperName();
        String createTimeBegin = sysOperLogQueryVo.getCreateTimeBegin();
        String createTimeEnd = sysOperLogQueryVo.getCreateTimeEnd();
        //封装条件
        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(title)){
            wrapper.like(SysOperLog::getTitle,title);
        }
        if (!StringUtils.isEmpty(operName)){
            wrapper.ge(SysOperLog::getOperName,operName);
        }
        if (!StringUtils.isEmpty(createTimeBegin)){
            wrapper.le(SysOperLog::getCreateTime,createTimeBegin);
        }
        if (!StringUtils.isEmpty(createTimeEnd)){
            wrapper.le(SysOperLog::getCreateTime,createTimeEnd);
        }
        IPage<SysOperLog> SysOperLogPage = sysOperLogMapper.selectPage(pageParam, wrapper);
        return SysOperLogPage;
    }
}
